package com.zhangbaiyan.test5;

import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author zhangbaiyan
 * @date 2024-09-24 21:57
 * @description:
 * @version:
 */
public class demo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建奖池
        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list,10,20,30,400,500,6000,70,80,900,100);

        //创建多线程要运行的参数对象
        MyCallable mc = new MyCallable(list);

        //创建多线程运行结果的管理者对象
        FutureTask<Integer> ft1 = new FutureTask<>(mc);
        FutureTask<Integer> ft2 = new FutureTask<>(mc);

        //创建线程对象
        Thread t1 = new Thread(ft1);
        Thread t2 = new Thread(ft2);

        t1.setName("抽奖员1");
        t2.setName("抽奖员2");

        t1.start();
        t2.start();
        System.out.println(ft1.get());
        System.out.println(ft2.get());
    }
}
